using System;
using System.Collections;

namespace XTCast.Mp3
{
	public enum TrackType {Queued=1,Playing,History}

	public class MP3Track:MP3File
	{
		public int id;
		public bool requested;
		public TrackType TrackType;

		private float elapsed;
		private long elapsedSet;
		private int bitRate;

		public virtual int BitRate {
			set {
				bitRate=value;
			}
			get {
				if (bitRate!=0) 
					return bitRate;
				else
					return base.BitRate;
			}
		}

		/// <summary>
		/// Elapsed in Milliseconds
		/// </summary>
		public virtual float Elapsed
		{
			set
			{
				elapsed = value;
				elapsedSet = System.DateTime.Now.Ticks;
			}
			get
			{
				float secSinceSet = (System.DateTime.Now.Ticks - elapsedSet) / (float)10000000;
				System.Diagnostics.Debug.Write(secSinceSet);
				if (secSinceSet > 10) return 0;
				return (elapsed + secSinceSet);
			}
		}
		
		public MP3Track(MP3File file):base(file)
		{
			id = GetNextID(this);
		}

		public static MP3Track GetTrack(int id) {
			return (MP3Track)idIndex[id];
		}

		static ArrayList idIndex= new ArrayList();
		protected internal static int GetNextID(MP3File f) {
			lock(typeof(XTCast.Mp3.MP3File)) {
				return idIndex.Add(f);
			}
		}
	}
}